﻿/// <reference path="back.bbs.main.js" />
/// <reference path="../../Shared/jquery-1.4.1-vsdoc.js" />

$(function () {
    $(".datepicker").datepicker({
           showOn:'both',
           buttonText:'选择日期',
        buttonImageOnly: true,        // 不把图标显示在按钮上，即去掉按钮
        buttonImage: $msg["AppRootPath"] + "Content/themes/other/calendar.gif",
        option: $.datepicker.regional["zh-CN"],
         changeMonth: true,   // 允许选择月份
         changeYear: true   // 允许选择年份
    });
     $(".datepicker").datepicker("option",
				$.datepicker.regional["zh-CN"]).attr("readonly", true);


});


// ajax 提交与验证
    // 创建结果显示层
    var divAjaxResult = $("#div_result");
    if (divAjaxResult.length == 0) {
        divAjaxResult = $("<div>", { id: "div_result",title:"提示信息" });
        divAjaxResult.appendTo($(document.body));
       
    }

    window.validateForm = function () { };

    window.ajaxForm = function () {
        $("form").ajaxForm({
            dataType: "html",
            beforeSubmit: window.validateForm,
            success: window.ajaxFormSuccess
        });
    };
    window.unloadForm = function (formId) {
        var a, b, isSubmit = true, c = formId == null ? "form" : "#" + formId;
        $("#btn_save").click(function () { isSubmit = false; });
        $(window).ajaxComplete(function () { if (ischange == false) { a = $(c).serialize(); } });
        if (a == undefined) { a = $(c).serialize(); }
        window.onbeforeunload = function () {
            b = $(c).serialize();
            if (a != undefined && a != b && isSubmit) { return $msg["Unload"]; }
        };
    }

    window.ajaxFormSuccess = function (html, statusText, xhr, $form) {
        if (html == "") { // sucess
            var url = $("#btn_save", $form).attr("url");
            if (url != undefined) {
                document.location.assign(url);
            }
        } else {
            var obj = null;
            try {
                obj = eval("(" + html + ")");
            } catch (e) {
            }
            if (obj != undefined && obj != null) {
                var dialogTitle = "提示信息";
                if (obj.title != undefined && obj.title != "") {
                    dialogTitle = obj.title;
                }
                divAjaxResult.html(obj.html);
                if (obj.result == 100) {
                    divAjaxResult.dialog({
                        autoOpen: true,
                        show: "blind",
                        title: dialogTitle,
                        width: 600,
                        modal: true,
                        buttons: {
                            "Ok": function () {
                                $(this).dialog("close");
                                var url = $("#btn_save", $form).attr("url");
                                if (url != undefined) {
                                    document.location.assign(url);
                                }
                            }
                        }
                    });
                } else {
                    divAjaxResult.html(obj.html);
                    divAjaxResult.dialog({
                        autoOpen: true,
                        show: "blind",
                        width: 600,
                        modal: true,
                        buttons: {
                            "Ok": function () {
                                $(this).dialog("close");
                            }
                        }
                    });
                }
            }
            else {
                divAjaxResult.html(html);
                var dialogTitle = "提示信息";
                var errorTitle = $("#errorTitle", divAjaxResult).html();
                if (errorTitle != null && errorTitle != undefined && errorTitle != "") {
                    dialogTitle = errorTitle;
                }
                divAjaxResult.dialog({
                    autoOpen: true,
                    show: "blind",
                    title: dialogTitle,
                    width: 600,
                    modal: true,
                    buttons: {
                        "Ok": function () {
                            $(this).dialog("close");
                        }
                        //                        "Cancel": function () {
                        //                            $(this).dialog("close");
                        //                        }
                    }
                });
            }

        }
    }